#include "thread.h"
#include <stdio.h>
#include <string.h>
Thread::Thread()
    : _pthid(0), _isRunning(false)
{
}
void Thread::start()
{
    if (!_isRunning)
    {
        int ret = pthread_create(&_pthid, nullptr, start_routine, this);
        if (ret != 0)
        {
            fprintf(stderr, "%s", strerror(ret));
            return;
        }
        _isRunning = true;
    }
}
void * Thread::start_routine(void * arg){
    Thread * thread = static_cast<Thread *> (arg);
    if(thread){
        thread->run();
    }
    return nullptr;
}
void Thread::join(){
    if(_isRunning){
        pthread_join(_pthid,NULL);
        _isRunning = false;
    }
}
